package com.horay.statemachiedemo.multi.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * Class description
 *
 * @author heyingcheng
 * @date 2020/10/23
 */
public enum OrderState {

    /**
     * 待支付
     */
    UNPAID(1, "待支付"),
    /**
     * 待收货
     */
    WAITING_FOR_RECEIVE(2, "待收货"),
    /**
     * 结束
     */
    DONE(3, "结束");

    public final Integer code;

    public final String comment;

    private static final Map<Integer, OrderState> MAP = new HashMap<>();

    static {
        OrderState[] values = OrderState.values();
        for (OrderState orderState : values) {
            MAP.put(orderState.code, orderState);
        }
    }

    OrderState(Integer code, String comment) {
        this.code = code;
        this.comment = comment;
    }

    public static OrderState valueOf(Integer code) {
        return MAP.get(code);
    }

}
